package com.wy._07Thread.atomicOperation;

import org.junit.Test;

/**
 * @author 吴宇~
 * @motto 我亦无他，唯手熟尔。
 * @edition jdk1.8
 * @reflection 0-1 喧闹任其喧闹，自由我自为之，我自风情万种，与世无争。
 * @date 2024/05/09/12:27
 * @target 心若有所向往，何惧道阻且长
 */
public class test1 {
   AtomicIntegerDemo atomicIntegerDemo = new AtomicIntegerDemo(1);

    @Test
    public void test() throws InterruptedException {
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + " - - " + atomicIntegerDemo.getAndIncrement());
            }
        });
        thread1.start();

        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + " - - " + atomicIntegerDemo.getAndIncrement());
            }
        });
        thread2.start();
        thread1.join();
        thread2.join();

        System.out.println(atomicIntegerDemo.getInitValue());
        System.out.println(atomicIntegerDemo.getNumberOfCalls());
    }
}
